package com.apobates.jforum2.troll.threads.mapper;

import com.apobates.jforum2.threads.stub.vo.ThreadsConfigVo;
import com.apobates.jforum2.troll.threads.entity.TopicConfig;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityTransformMapper;
import java.util.Optional;
import java.util.function.Function;

/**
 *
 * @author xiaofanku
 */
public class ThreadsConfigVoMapperEntity implements OptionalEntityTransformMapper<TopicConfig, ThreadsConfigVo>{
    @Override
    public Optional<ThreadsConfigVo> transform(Optional<TopicConfig> entity) {
        return entity.map(ins->{
            return mapper().apply(ins);
        });
    }

    public static Function<TopicConfig,ThreadsConfigVo> mapper(){
        return topicConfig -> {
            ThreadsConfigVo tcv = new ThreadsConfigVo();
            tcv.setId(topicConfig.getId());
            //话题ID
            tcv.setThreads(topicConfig.getTopicId());
            //是否是私人的
            //false(0)表示公开,谁都可以看/true(1)只有我的圈可以看
            tcv.setPrivacy(topicConfig.isPrivacy());
            //是否允许回复|是否允话评论,true(1)允许,false(0)不允许
            tcv.setReply(topicConfig.isReply());
            //开启回复通知,true(1)开启,false(0)不通知
            tcv.setNotify(topicConfig.isNotify());
            //A读
            // 积分需求
            tcv.setReadMinScore(topicConfig.getReadMinScore());
            // 会员组需求
            tcv.setReadLowMemberGroup(topicConfig.getReadLowMemberGroup().getSymbol());
            // 会员角色需求
            tcv.setReadLowMemberRole(topicConfig.getReadLowMemberRole().getSymbol());
            // 角色会员等级需求
            tcv.setReadLowMemberLevel(topicConfig.getReadLowMemberLevel());

            //B写
            // 积分需求
            tcv.setWriteMinScore(topicConfig.getWriteMinScore());
            // 会员组需求
            tcv.setWriteLowMemberGroup(topicConfig.getWriteLowMemberGroup().getSymbol());
            // 会员组需求
            tcv.setWriteLowMemberRole(topicConfig.getWriteLowMemberRole().getSymbol());
            // 角色会员等级需求
            tcv.setWriteLowMemberLevel(topicConfig.getWriteLowMemberLevel());
            //b.1是否每人只能回一次|福利只能领一次,true(1)只一次,false(0)不限次数
            tcv.setAtomPoster(topicConfig.isAtomPoster());
            //b.2回复的最大楼层次|不间断由某个人回复[不是话题的作者能决定]
            //b.3回复的时间上限|超过N天不允许再回复了[不是话题的作者能决定]
            // 同一会员不间断的回贴的数量
            tcv.setWriteMinInterrupt(topicConfig.getWriteMinInterrupt());
            return tcv;
        };
    }
}